﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ManagedServices.UI.Web.Models;

namespace ManagedServices.UI.Web.Controllers
{
    public class ManageSubServiceController : Controller
    {
        //
        // GET: /ManageSubService/

        public ActionResult Index()
        {
            SubServiceMetadataModel[] subServices = DTOConverter.GetSubServices();
            return View(subServices);
        }

        [HttpGet]
        public ActionResult EditSubService(string id)
        {
            Guid ssID = new Guid(id);
            SubServiceMetadataModel selectedSubService = DTOConverter.GetSubService(ssID);

            return View(selectedSubService);
        }

        public ActionResult CreateSubServiceInstance(string id)
        {
            Guid ssID = new Guid(id);
            SubServiceInstanceModel selectedSubService = DTOConverter.GetSubServiceInstance(ssID);
            return View(selectedSubService);
        }

        [HttpPost]
        public ActionResult CreateSubServiceInstance(SubServiceInstanceModel model)
        {
            if (ModelState.IsValid)
            {
                DTOConverter.CreateSubServiceInstance(model);
                return RedirectToAction("Index", "Home");
            }
            ModelState.AddModelError("", "There was a error in creating the SubService Instance");
            return View(model);
        }
    }
}
